package zuk.clipvietfun.clip;

import java.util.List;

import zuk.clipvietfun.R;
import zuk.clipvietfun.loadimageview.ImageLoader;
import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ClipAdapter extends ArrayAdapter<Clip> {
	Context context;
	private List<Clip> listClip;
	ImageLoader imageLoader;
	public ClipAdapter(Context context,int textViewResourceId,List<Clip> listClip) {
		super(context, textViewResourceId, listClip);
		this.context = context;
		this.listClip = listClip;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater infalInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = infalInflater.inflate(R.layout.clip, null);
		}
		Clip clip = listClip.get(position);
		TextView tViewTitle = (TextView) v.findViewById(R.id.text_title);
		Log.e("!!!!!!!!!", "Load " + clip.title);

		tViewTitle.setText(Html.fromHtml(clip.getTitle()));
		//		ImageHolder imgHolder = new ImageHolder();
		//		imgHolder.setImg_thumb((ImageView) v.findViewById(R.id.img_thumb));
		//		imgHolder.getImg_thumb().setTag(position);
		//		imgHolder.setPrgBar((ProgressBar) v.findViewById(R.id.prgBar));
		//		imgHolder.setImg_url(clip.imgurl);
		//		imgHolder.setPosition(position);
		////		new LoadImageTask(imgHolder).execute();

		ImageView img_thumb = (ImageView) v.findViewById(R.id.img_thumb);
		ProgressBar prgBar = (ProgressBar) v.findViewById(R.id.prgBar);
		if(clip.imgurl!=null)
			imageLoader.DisplayImage(clip.imgurl, img_thumb,prgBar);
		return v;
	}

}
